package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketSearchHistory;
import com.cskaoyan.market.db.domain.MarketSearchHistoryExample;
import com.cskaoyan.market.db.mapper.MarketSearchHistoryMapper;
import com.cskaoyan.market.service.AdminHistoryService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AdminHistoryServiceImpl implements AdminHistoryService {

    @Autowired
    MarketSearchHistoryMapper mapper;

    @Override
    @Transactional
    public List<MarketSearchHistory> list(Integer page, Integer limit, Integer userId, String keyword, String sort, String order) {

        MarketSearchHistoryExample marketSearchHistoryExample = new MarketSearchHistoryExample();
        MarketSearchHistoryExample.Criteria criteria = marketSearchHistoryExample.createCriteria();
        if(userId!=null)
            criteria.andUserIdEqualTo(userId);
        if(!StringUtils.isEmpty(keyword))
            criteria.andUserIdEqualTo(Integer.parseInt(keyword));
        marketSearchHistoryExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(page,limit);
        List<MarketSearchHistory> marketSearchHistoryList = mapper.selectByExample(marketSearchHistoryExample);
        return marketSearchHistoryList;
    }
}
